package com.laiketui.mch.util;

import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.Objects;

public class PriceUtil {
    //税费扣8个点
    private static final long taxRate = 0L;
//    private static final long taxRate = 8L;
    public static final BigDecimal RATE_MU = new BigDecimal("0.01");
    public static final BigDecimal RATE_SU = new BigDecimal("100");

    public static Long bigDecimalToLongPrice(BigDecimal price) {
        if (Objects.nonNull(price)) {
            return RATE_SU.multiply(price).setScale(2, RoundingMode.UP).longValue();
        }
        return 0L;
    }

    public static BigDecimal longToBigDecimalPrice(Long price) {
        if (Objects.nonNull(price)) {
//            return RATE_MU.multiply(new BigDecimal(price)).setScale(2, RoundingMode.UP);
            //改为多收一元钱
            return RATE_MU.multiply(new BigDecimal(price)).setScale(0, RoundingMode.UP);
        }
        return BigDecimal.ZERO;
    }

    public static Long longRateToLong(Long a, Long b) {
        if(Objects.isNull(a) || Objects.isNull(b)){
            return 0L;
        }
        long c = a * b;
        return new BigDecimal(Long.toString(c)).multiply(RATE_MU).setScale(0, RoundingMode.UP).longValue() ;
    }


    public static Long calcTaxRate(Long a) {
        if(Objects.isNull(a)){
            return 0L;
        }
        long c = a * taxRate;
        return new BigDecimal(Long.toString(c)).multiply(new BigDecimal("0.0001")).setScale(0, RoundingMode.UP).multiply(new BigDecimal("100")).longValue() ;
    }

    public static void main(String[] args) {
        long a = 583000L;
        System.out.println(calcTaxRate(a));
    }
}
